#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    setUpVideo();
    setUpGui();

    media->play();
    //video->setFullScreen(true);
}

void MainWindow::setUpVideo()
{
    video = new Phonon::VideoWidget(this);

    // Create a mediasource to use as a source for a media object
    const QString url = "/home/erik/Videos/big_buck_bunny_480p_h264.mov";
    MovieSocket * ms = new MovieSocket(url);
    source = new Phonon::MediaSource(ms);
    media = new Phonon::MediaObject(this);
    media->setCurrentSource(*source);

    // To be able to hear the sound from the movie
    audio = new Phonon::AudioOutput(Phonon::VideoCategory, this);

    // Connect the media object with both VideoWidget and the AudioOutput
    Phonon::createPath(media, video);
    Phonon::createPath(media, audio);
}

void MainWindow::setUpGui()
{
    // Make a seek slider
    Phonon::SeekSlider * seekSlider = new Phonon::SeekSlider(this);
    seekSlider->setMediaObject(media);
    seekSlider->setTracking(false);

    // Set layout for the current window
    QVBoxLayout * mainLayout = new QVBoxLayout(this);
    mainLayout->addWidget(video);
    mainLayout->addStretch();
    mainLayout->addWidget(seekSlider);

    // Set the main widget that "holds" the entire layout
    QWidget * mainWidget = new QWidget;
    mainWidget->setLayout(mainLayout);
    setCentralWidget(mainWidget);

    seekSlider->show();
    video->show();
}

MainWindow::~MainWindow()
{

}
